import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let TOKEN = 'SET_TOKEN'

import { setItem, getItem,removeItem } from '@/utlis/storage'

export default new Vuex.Store({
  state: {
    user: getItem(TOKEN) || null
  },
  mutations: {
    setUser(state, user) {
      state.user = user

      setItem(TOKEN, user)
    },
    //清除token
    rmToken(state){
      /* 点击退出登录 
      1-清除state中的user
      2-清除本地缓存
      */
      state.user=null
      removeItem(TOKEN)
    }
  },
  actions: {
  },
  modules: {
  }
})
